package com.eight.clientcourse.service.impl;

import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.eight.clientcourse.dao.EduVideoDao;
import com.eight.clientcourse.dao.OrderDao;
import com.eight.clientcourse.dao.ShouCangTeacherDao;
import com.eight.clientcourse.service.OrderService;
import com.eight.clientcourse.vo.GuanZhuVo;
import com.eight.common.pojo.EduTeacher;
import com.eight.common.pojo.EduVideo;
import com.eight.common.pojo.TOrder;
import com.eight.common.pojo.TbShoucangTeacher;
import com.eight.common.vo.Result;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * @program: qy8-education1
 * @description:
 * @author: 张亚祥
 * @create: 2023-06-03 15:00
 **/
@Service
public class OrderServiceImpl implements OrderService {
    @Resource
    private OrderDao orderDao;

    @Resource
    private EduVideoDao eduVideoDao;

    @Resource
    private ShouCangTeacherDao shouCangTeacherDao;


    @Override
    public List<TOrder> findOrderByMemberByCourse(String cid, String memberId) {
        List<TOrder> orderByMemberByCourse = orderDao.findOrderByMemberByCourse(cid, memberId);
        return orderByMemberByCourse;
    }

    @Override
    public EduTeacher findTeacherStatus(String teacherId,String memberId) {
        EduTeacher eduTeacher = shouCangTeacherDao.findByTeacherStatus(teacherId,memberId);
        return eduTeacher;
    }


    @Override
    public int insertShouCangTercher(TbShoucangTeacher tbShoucangTeacher) {
        QueryWrapper<EduTeacher> wrapper=new QueryWrapper<>();
        List<EduTeacher> eduTeacher = shouCangTeacherDao.addByTeacherStatus(wrapper);
        if(eduTeacher!=null){
            wrapper.eq("status","0");
            tbShoucangTeacher.setId(IdUtil.getSnowflakeNextIdStr());
            tbShoucangTeacher.setMemberId(tbShoucangTeacher.getMemberId());
            tbShoucangTeacher.setTeacherId(tbShoucangTeacher.getTeacherId());
            int insert = shouCangTeacherDao.insert(tbShoucangTeacher);
        }
        return 0;
    }

    @Override
    public List<EduVideo> findChapterById(String id) {
        QueryWrapper<EduVideo> wrapper =new QueryWrapper<>();
        if(StringUtils.hasText(id))
        {
            wrapper.eq("course_id",id);
        }
        List<EduVideo> eduVideos = eduVideoDao.selectList(wrapper);
        return eduVideos;
    }

    @Override
    public int deleteAttentionTeacher(GuanZhuVo guanZhuVo) {
        QueryWrapper<TbShoucangTeacher> wrapper = new QueryWrapper<>();
        wrapper.eq("teacher_id",guanZhuVo.getTeacherId());
        wrapper.eq("member_id",guanZhuVo.getMemberId());
        int delete = shouCangTeacherDao.delete(wrapper);
        return 0;
    }


}
